"""
插件开发模板
提供标准的插件开发模板和基类
"""

from abc import ABC, abstractmethod
from typing import Dict, Any, List, Optional
import logging
import asyncio


class BasePlugin(ABC):
    """插件基类"""
    
    def __init__(self, config: Dict[str, Any]):
        self.config = config
        self.name = config.get("name", self.__class__.__name__)
        self.version = config.get("version", "1.0.0")
        self.logger = logging.getLogger(f"plugin.{self.name}")
        self.enabled = config.get("enabled", True)
    
    @abstractmethod
    async def initialize(self) -> bool:
        """初始化插件"""
        pass
    
    @abstractmethod
    async def execute(self, data: Any = None) -> Any:
        """执行插件功能"""
        pass
    
    async def cleanup(self):
        """清理资源"""
        pass


class DataSourcePlugin(BasePlugin):
    """数据源插件基类"""
    
    @abstractmethod
    async def connect(self) -> bool:
        """连接数据源"""
        pass
    
    @abstractmethod
    async def fetch_data(self, query: Dict[str, Any]) -> List[Dict[str, Any]]:
        """获取数据"""
        pass
    
    @abstractmethod
    async def close(self):
        """关闭连接"""
        pass


class ProcessorPlugin(BasePlugin):
    """处理器插件基类"""
    
    @abstractmethod
    async def process(self, data: List[Dict[str, Any]]) -> List[Dict[str, Any]]:
        """处理数据"""
        pass


class OutputPlugin(BasePlugin):
    """输出插件基类"""
    
    @abstractmethod
    async def output(self, data: Any, destination: str) -> bool:
        """输出数据"""
        pass